package org.teremail.smtp;

import java.io.IOException;
import java.nio.charset.Charset;

import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoFilter;
import org.apache.mina.common.SimpleByteBufferAllocator;
import org.apache.mina.filter.LoggingFilter;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
import org.junit.Ignore;
import org.teremail.common.Log;

@Ignore
public class ServerTestCase {
    
    private final static Log log = Log.getLog(ServerTestCase.class);
    
    public void runServer(int port) throws IOException, InterruptedException {
        
        ByteBuffer.setUseDirectBuffers(false);
        ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
        SocketAcceptorConfig cfg = new SocketAcceptorConfig();
        cfg.getFilterChain().addLast("logger", new LoggingFilter());
        IoFilter textProto = new ProtocolCodecFilter(
                new TextLineCodecFactory(Charset.forName("US-ASCII")));
        cfg.getFilterChain().addLast("codec", new ConditionalFilter(textProto));
        
        log.info("Server Started, listening on port: %s", port);
    }
    
    public static void main(String[] args) throws IOException, InterruptedException {
        new ServerTestCase().runServer(9025);
    }
}
